﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace MineSweeping.AppCode.Tops
{
    //public class IndexConverter : IValueConverter
    //{
    //    public object Convert(object value, Type TargetType, object parameter, CultureInfo culture)
    //    {
    //        ListBoxItem item = (ListBoxItem)value;
    //        ListBox listView = ItemsControl.ItemsControlFromItemContainer(item) as ListBox;
    //        int index = listView.ItemContainerGenerator.IndexFromContainer(item);
    //        return index.ToString("D2");
    //    }

    //    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    //    {
    //        throw new NotImplementedException();
    //    }
    //}

    public class RankConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int showtime = (int)value;
            return showtime.ToString("D2");
        }

        // Not need here
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class ScoreConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int score = (int)value;

            if (score == -1)
            {
                return "--";
            }

            return score.ToString("D3");
        }

        // Not need here
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class DateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime dateTime = (DateTime)value;

            if(dateTime == DateTime.MaxValue)
            {
                return "--";
            }

            return dateTime.ToString("yyyy-MM-dd");
        }

        // Not need here
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
